import { v4 as uuidv4 } from 'uuid';
//生成随机字符串，每次执行不发生变化，游客身份持久存储
export const getUUID = () => {
    //本地存储获取uUId
    let uuid_token = localStorage.getItem('UUIDTOKEN');
    if (!uuid_token) {
        //生成uuid
        uuid_token = uuidv4();
        //本地存储uuid
        localStorage.setItem('UUIDTOKEN', uuid_token);
    }
    return uuid_token;
}

//用于将token存入localStorage
export function saveToken(token){
    localStorage.setItem('token',token)
  }
  
  //用于从localStorage中读取token
  export function readToken(){
    return localStorage.getItem('token')
  }
  
  //从localStoragre删除用户token
  export function deleteToken(){
    localStorage.removeItem('token')
  }